//
//  AppHttpClient.m
//  XiaoMiao
//
//  Created by kinglian_iOS_000 on 2018/2/5.
//  Copyright © 2018年 smallyou. All rights reserved.
//

#import "AppHttpClient.h"

@implementation AppHttpClient

+ (AppURLSessionTask *)getCodeWithPhone:(NSString *)phone completion: (void(^)(BOOL success, NSString *errorMsg))completion {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"phone"] = phone;
    param[@"prix"] = @"86";
    
    AppURLSessionTask *task = [AppNetwork getWithUrl:kGetCodeUrl refreshCache:NO params:param success:^(id response) {
        if (completion) {
            completion(YES, nil);
        }
    } fail:^(AppError *error) {
        if (completion) {
            completion(NO, [error errorMessage]);
        }
    }];
    
    return task;
}
 

/**上传图片*/
+ (void)userModule_uploadImage:(UIImage *)image completion:(void(^)(BOOL success, NSString *imageUrl, NSString *errorMsg))completion
{
    [AppNetwork uploadWithImage:image url:kUploadPhotoUrl parameters:nil progress:^(int64_t bytesCompleted, int64_t totalBytes) {
        NSLog(@"------->正在上传图片");
    } success:^(id response) {
        if ([response[@"statusCode"] intValue] == 200) {
            if (completion) {
                completion(YES, response[@"imageUrl"], nil);
            }
        }else {
            if (completion) {
                completion(NO, nil, [NSString stringWithFormat:@"上传失败%@", response[@"statusCode"]]);
            }
        }
        
    } fail:^(AppError *error) {
        if (completion) {
            completion(NO, nil, [error errorMessage]);
        } 
    }];
}


@end


/*
 
 + (AppURLSessionTask *)uploadImage:(UIImage *)image completion:(void(^)(BOOL success, NSString *errorMsg))completion {
 AppURLSessionTask *task = [AppNetwork uploadWithImage:image url:kUploadPhotoUrl parameters:nil progress:nil success:^(id response) {
 if ([response[@"statusCode"] intValue] == 200) {
 if (completion) {
 completion(YES, nil);
 }
 }else {
 if (completion) {
 completion(NO, [NSString stringWithFormat:@"上传失败%@", response[@"statusCode"]]);
 }
 }
 } fail:^(AppError *error) {
 if (completion) {
 completion(NO, [error errorMessage]);
 }
 }];
 
 return task;
 }
 
 */

